<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ES6 对于对象写法的更新</title>
</head>
<body>
    
</body>
</html>
<script>
    // 对象里函数的简写
    // 原写法
    /**
    var obj ={
        myname:"zs",
        fn:()=>{
            console.log("fn");
        }
    }
    obj.fn();
    */
    // 箭头简写
    var obj5 ={
        myname:"zs",
        fn:()=>{
            console.log("fn");
        }
    }
    obj5.fn();
    // 普通简写
    var obj1 = {
        myname:"zs",
        fn(){
            console.log("fn");
        }
    }
    obj1.fn();



    // 键名和键值相同的时候可以简写
    var myname = "zs";
    var obj2 ={
        // myname:myname,  //相同了
        myname,
        age:20,
        height:"178cm"
    }
    console.log(obj2);



    // 动态的键名：键名可以是变量
    var myage = "age";
    var str = "hello";
    var obj3 ={
        myname:"zs",
        // myage:myage //是变量
        [myage]:myage,
        [str+"00"]:"你好"
    }
    console.log(obj3);



    // 数组去重
    var arr = ["a","b","c","d","a","b"];
    var obj6={}
    for(let i=0;i<arr.length;i++){
        console.log(arr[i]);
        obj6[arr[i]]=1;
    }
    console.log(obj6);
    var newarr = [];
    for(let key in obj6){
        newarr.push(key);
    }
    console.log(newarr);



    // 统计arr1里 字符出现的次数
    var arr1 = ["a","b","c","b","a","b"];
    var obj7={}
    for(var i=0;i<arr1.length;i++){
        key = arr1[i];
        if(obj7[key]){
            obj7[key]++;
        }else{
            obj7[key]=1;
        }
    }
    for(var key in obj7){
        console.log(key+"出现了"+obj7[key]+'次');
    }



</script>